const { saveFile, findFileList } = require('../services/file')
const { SuccessModel, ErrorModel } = require('../model/ModelInfo')
const { saveFileError, findFileListError } = require('../model/ErrorInfo')

async function getFileInfo ({destination, filename, path, size, mimetype}) {
  const result = await saveFile({destination, filename, path, size, mimetype})
  if (!result) {
    return new ErrorModel(saveFileError)
  }
  return new SuccessModel(result)
}

async function getFileList ({ fileids }) {
  const result = await findFileList({ fileids })
  if (!result) {
    return new ErrorModel(findFileListError)
  }
  return new SuccessModel(result)
}

module.exports = {
  getFileInfo,
  getFileList
}
